package com.auemall.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.auemall.constant.ApplicationConstant;
import com.auemall.po.ProductBrand;
import com.auemall.service.ProductBrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Controller
public class BrandController {

	@Autowired
	private ProductBrandService productBrandService;
	
	//显示所有的品牌信息
	@RequestMapping("/brand/list")
	
	public String showBrand(HttpServletRequest request,Integer currentPage) {
		
		if (currentPage == null || currentPage <=0) {
			
			currentPage = 1;
		}
				
		PageHelper.startPage(currentPage, ApplicationConstant.PAGE_SIZE);
		
		
		List<ProductBrand> list = productBrandService.findProductBrandAll();
		
		//如果不了解PageInfo的属性，可以访问http://www.cnblogs.com/digdeep/p/4608933.html连接了解
		
		PageInfo<ProductBrand> pageInfo = new PageInfo<ProductBrand>(list);
		
		request.setAttribute("pageview",pageInfo);
		
		return "brand/bandList";
	}
	
	//品牌的详细信息
	@RequestMapping("/brand/detail")
	
	public String showBrandDetail(Integer id,HttpServletRequest request) {
		
		ProductBrand brand = this.productBrandService.selectByPrimaryKey(id);
		
		//保存值到session
		request.setAttribute("brand",brand);
		
		return "brand/bandDetail";
	}
	
	
}
